package cn.edu.scau.cmi.xiaozhenlin.composite;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;

public class CompositeCtrl {

	@FXML
	private TextArea et_name;

	@FXML
	private Button btn_add;

	@FXML
	private Button btn_child;

	@FXML
	private TextArea tv_show;

	private SafeComposite root = null;

	private StringBuilder stringbuilder = new StringBuilder();

	@FXML
	void add(MouseEvent event) {
		root = new SafeComposite(et_name.getText().toString());
		et_name.clear();
		stringbuilder = root.printStruct();
		tv_show.setText(stringbuilder.toString());
	}

	@FXML
	void addChild(MouseEvent event) {
		if (root == null) {
			tv_show.setText("错误！未生成目录！");
		} else {
			SafeLeaf leaf = new SafeLeaf(et_name.getText().toString());
			root.addChild(leaf);
			et_name.clear();
			stringbuilder = root.printStruct();
			tv_show.setText(stringbuilder.toString());
		}
	}

	@FXML
	public void deleteChild() {
		root.removeChild(et_name.getText().toString());
		et_name.clear();
		stringbuilder = root.printStruct();
		tv_show.setText(stringbuilder.toString());
	}

}
